﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;

namespace Ideas2Realize.Data
{
    public class CustomPrincipal : IPrincipal
    {
        
        private string[] _myroles;
        
        private IIdentity _myidentity;

        public CustomPrincipal(IIdentity identity, string[] roles) {
            _myidentity = identity;
            _myroles = new string[roles.Length];
            roles.CopyTo(_myroles, 0);
            Array.Sort(_myroles);
        }
        
        public IIdentity Identity { get { return _myidentity; } }
        
        public bool IsInRole(string role) { return Array.BinarySearch(_myroles, role) >= 0 ? true : false; }

    }
}
